import { useStatementStore } from '@/store'

export default function useContextmenu() {
  const { setVisible } = useStatementStore()

  const left = ref(0)
  const top = ref(0)
  const rowIndex = ref(-1)

  function onContextmenu(evt: MouseEvent, index: number) {
    evt.preventDefault()
    const { clientX, clientY } = evt

    left.value = clientX
    top.value = clientY

    setVisible(true)
    rowIndex.value = index
  }

  return {
    left,
    top,
    rowIndex,

    onContextmenu,
  }
}
